#include "stdafx.h"
#include "Mutex.h"


Thread_Mutex::Thread_Mutex()
{
	mMutex = CreateMutex( 
        NULL,              // default security attributes
        FALSE,             // initially not owned
        NULL); 
}

Thread_Mutex::~Thread_Mutex()
{
	CloseHandle(mMutex);
}

void Thread_Mutex::acquire()
{
	WaitForSingleObject(mMutex,INFINITE);
}

void Thread_Mutex::release()
{
	ReleaseMutex(mMutex);
}

Thread_Mutex_Guard::Thread_Mutex_Guard(Thread_Mutex &m)
 : mutex(m)
{
	mutex.acquire();
}

Thread_Mutex_Guard::~Thread_Mutex_Guard()
{
	if(_owner)
		mutex.release();
}
